﻿/******************************************************************
** 文件名:T114_GoodBrand_ItemDAL.cs
** Copyright (c) 
** 创建人:佟礼
** 日 期:2012-07-09 17:44:24
** 描 述:数据操作类
********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Data;
using Enter.DataProxy.DbConnector;
using Enter.Entity;
using Enter.DataProxy.Mail.Base;
using Enter.Config;
namespace Enter.DataProxy.Mail
{
    /// <summary>
    /// 数据操作类：T114_GoodBrand_ItemManager
    /// </summary>
    public class T114_GoodBrand_ItemManager : DataProxyManager, IT114_GoodBrand_ItemManager
    {
        public T114_GoodBrand_ItemManager() :
            base(ProxyProvider.ConfigurationName, ProxyProvider.ConfiruationDbName) { }
        #region 插入记录
        /// <summary>
        /// 插入记录
        /// </summary>
        /// <returns></returns>
        public int Insert(T114_GoodBrand_ItemEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            var db = base.CreateDbWriter();
            strSql.Append("INSERT INTO T114_GoodBrand_Item");
            strSql.Append("(BNO,GoodClassID,status)");
            strSql.Append(" values ");
            strSql.Append("(@BNO,@GoodClassID,@status)");
            ParameterCollection parameters = CreateParameter();
            parameters.Append("BNO", model.BNO, DbType.String);
            parameters.Append("GoodClassID", model.GoodClassID, DbType.Int32);
            parameters.Append("status", model.status, DbType.Int32);
            return db.ExecuteNonQuery(strSql.ToString(), parameters);
        }
        #endregion

        #region 更新数据
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <returns></returns>
        public int Update(T114_GoodBrand_ItemEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            var db = base.CreateDbWriter();
            strSql.Append("UPDATE T114_GoodBrand_Item SET ");
            strSql.Append("BNO=@BNO,GoodClassID=@GoodClassID,status=@status");
            strSql.Append(" WHERE ID=@ID");
            ParameterCollection parameters = CreateParameter();
            parameters.Append("ID", model.ID, DbType.Int32);
            parameters.Append("BNO", model.BNO, DbType.String);
            parameters.Append("GoodClassID", model.GoodClassID, DbType.Int32);
            parameters.Append("status", model.status, DbType.Int32);
            return db.ExecuteNonQuery(strSql.ToString(), parameters);
        }
        #endregion

        #region IEntityFacade 成员
        /// <summary>
        /// 填充数据
        /// </summary>
        /// <param name="reader"></param>
        public T114_GoodBrand_ItemEntity FillDetailWithReader(IDataReader reader)
        {
            T114_GoodBrand_ItemEntity model = new T114_GoodBrand_ItemEntity();
            if (reader["ID"] != DBNull.Value)
                model.ID = (int)reader["ID"];
            if (reader["BNO"] != DBNull.Value)
                model.BNO = (string)reader["BNO"];
            if (reader["GoodClassID"] != DBNull.Value)
                model.GoodClassID = (string)reader["GoodClassID"];
            if (reader["status"] != DBNull.Value)
                model.status = (EnumStatus)(byte)reader["status"];
            return model;
        }
        #endregion

        #region 根据ID获取一个对象
        public T114_GoodBrand_ItemEntity GetObjectByID(int ID)
        {
            string sql = "SELECT TOP 1 * FROM T114_GoodBrand_Item  WHERE ID=@ID";
            var db = base.CreateDbReader();
            ParameterCollection parameters = CreateParameter();
            parameters.Append("ID", ID, DbType.Int32);
            try
            {
                IDataReader reader = db.ExecuteReader(sql, parameters);
                if (reader.Read())
                {
                    return this.FillDetailWithReader(reader);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return null;
        }
        #endregion

        #region 删除数据
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns></returns>
        public int Delete(int ID)
        {
            var db = base.CreateDbWriter();
            string strSql = "DELETE T114_GoodBrand_Item WHERE ID=@ID";
            ParameterCollection parameters = CreateParameter();
            parameters.Append("ID", ID);
            return db.ExecuteNonQuery(strSql.ToString(), parameters);
        }
        #endregion

        #region 数据集
        public IList<T114_GoodBrand_ItemEntity> ShowList()
        {
            var db = base.CreateDbReader();
            string strSql = "SELECT  * FROM T114_GoodBrand_Item";
            IList<T114_GoodBrand_ItemEntity> result = null;
            result = db.Execute<T114_GoodBrand_ItemEntity>(strSql);
            return result;
        }
        #endregion

        #region 数据集
        public DataTable ShowTable()
        {
            var db = base.CreateDbReader();
            string strSql = "SELECT  * FROM T114_GoodBrand_Item";
            return db.ExecuteDataSet(strSql.ToString()).Tables[0];
        }
        #endregion

        #region 分页数据集
        public DataTable ShowTable(PageEntity entity, out int totalPages, out int totalCount)
        {
            BaseManager manager = new BaseManager();
            entity.tbName = "T114_GoodBrand_Item";
            DataTable dt = manager.GetTable(entity);
            totalPages = entity.TotalPages;
            totalCount = entity.TotalCount;
            return dt;
        }
        #endregion
    }
}
